package com.gopay.bis.service.bank.autoroute;

import javax.annotation.Resource;

import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.domain.bis.BaseBisBankExtConfig;
import com.gopay.common.domain.bis.RouteMessage;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.autoroute.BankRoute;
import com.gopay.remote.bank.autoroute.RouteAlarm;

/**
 * 银行自动路由抽象类
 * 
 * @BankRouteBase.java
 * @author zhengxue
 * @2016-10-8 下午2:43:31 www.gopay.com.cn Inc.All rights reserved.
 */
public abstract class BankRouteBase implements BankRoute {
    @Resource(name = "smsRouteAlarm")
    private RouteAlarm smsRouteAlarm;

    @Override
    public BaseBisBankExtConfig getRoute(RouteMessage routeMessage) throws GopayException {
        BaseBisBankExtConfig bankConfig = getBankRoute(routeMessage);
        if (null == bankConfig) {
//            bankRouteAlarm(routeMessage);
            throw new GopayException(ProcCodeConstants.PROC_CODE_100E7021);
        }
        return bankConfig;
    }

    @Override
    public BaseBisBankExtConfig getNormalRoute(RouteMessage routeMessage) throws GopayException {
        BaseBisBankExtConfig bankConfig = getNormalBankRoute(routeMessage);
        if (null == bankConfig) {
//            bankRouteAlarm(routeMessage);
            throw new GopayException(ProcCodeConstants.PROC_CODE_100E7021);
        }
        return bankConfig;
    }

    public void bankRouteAlarm(RouteMessage req) {
        req.setSpecial(req.getBankCode() + ": " + req.getGopayOrderId() + " 未获取到银行产品通道 . ");
        smsRouteAlarm.bankRouteAlarm(req);
    }

    /**
     * 自动路由获取银行渠道信息
     * 
     * @param routeMessage
     * @return
     */
    protected abstract BaseBisBankExtConfig getBankRoute(RouteMessage routeMessage);

    /**
     * 获取通用方案银行渠道信息
     * 
     * @param routeMessage
     * @return
     */
    protected abstract BaseBisBankExtConfig getNormalBankRoute(RouteMessage routeMessage);

}
